// components/map/map.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    marker:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  // tabtab(e){
  //   var inx = this.data.marker
  //   for(var i = 0 ; i<inx.length ; i++){
  //     if(inx.length == 1) {
  //       return
  //     }
  //   }
  // },
  jupe(){
    wx.redirectTo({
      url:"../shebeizhibo/shebeizhibo"
    })
  },
  tabtab:function(e){
    wx.redirectTo({
      url:"../zhibojian/zhibojian?id="+e.detail.markerId
    })
  },
  onLoad: function (options) {
    var that = this;
    wx.getLocation({
      isHighAccuracy:true,
      type: 'gcj02',
      success: (res) => {
        that.setData({
          marker:[
            {
              latitude:res.latitude,
              longitude:res.longitude,
              iconPath:'../../assate/dingwei.png',
              width:30,
              height:40,
              id:0,
              callout:{
                  content:'当前位置',
                  color:"red",
                  fontSize:13,
                  borderColor:"red",
                  borderWidth:1,
                  borderRadius:5,
                  padding:5,
                  display:"ALWAYS",
                  
              }
            }
          ]
        })
      }
    })

  },
  //查看周围直播时候的事件
  clicklook(e){
    
    var that = this
    var db = wx.cloud.database()
    db.collection('mapData').get({
      success: function(res) {
        var result = res.data
        result.forEach((item,index) => {
          let markers = "marker["+(index+1)+"]"
          that.setData({
            [markers]: {
              latitude:item.lat,
              longitude:item.lng,
              iconPath:'../../assate/dingwei2.png',
              id:item.id,
              width:30,
              height:40,
              callout:{
                  content:item.content,
                  color:"red",
                  fontSize:13,
                  borderColor:"red",
                  borderWidth:1,
                  borderRadius:5,
                  padding:5,
                  display:"BYCLICK",
              }
            }
          })
        })
     }
    })
  },
  bindlooklook(){
    wx.redirectTo({
      url:"../looklook/looklook",
    })
    console.log(123)
  }
})
